package com.lc.zpyh.widget;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentTransaction;


/**
 * Created by Administrator on 2016/11/16.
 */

public class UIHelper {

    /**
     * add Fragment
     *
     * @param activity
     * @param res
     * @param target
     * @param data
     */
    public static void addFragment(FragmentActivity activity, int res, String target, Bundle data) {
        Fragment fragment = Fragment.instantiate(activity, target, data);
        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
        ft.add(res, fragment);
        ft.commit();
    }

    /**
     * 添加到返回栈
     *
     * @param activity
     * @param res
     * @param target
     * @param data
     */
//    public static void addFragmentToBack(FragmentActivity activity, int res, String target, Bundle data) {
//        Fragment fragment = Fragment.instantiate(activity, target, data);
//        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
//        ft.setCustomAnimations(R.anim.anim_in, R.anim.anim_out, 0, R.anim.anim_left_to_right);
//        ft.add(res, fragment);
//        ft.addToBackStack(target);
//        ft.commit();
//    }

    /**
     * replace Fragment
     *
     * @param activity
     * @param res
     * @param target
     * @param data
     */
    public static void replaceFragment(FragmentActivity activity, int res, String target, Bundle data) {
        Fragment fragment = Fragment.instantiate(activity, target, data);
        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
        ft.replace(res, fragment);
        ft.commit();
    }

    /**
     * 添加到返回栈
     *
     * @param activity
     * @param res
     * @param target
     * @param data
//     */
//    public static void replaceFragmentToBack(FragmentActivity activity, int res, String target, Bundle data) {
//        Fragment fragment = Fragment.instantiate(activity, target, data);
//        FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
//        ft.setCustomAnimations(R.anim.anim_in, R.anim.anim_out, 0, R.anim.anim_left_to_right);
//        ft.replace(res, fragment);
//        ft.addToBackStack(target);
//        ft.commit();
//    }

    /**
     * 界面跳转
     *
     * @param cls
     */
    public static void startActivity(Context context, Class cls) {
        checkNotNull(cls);
        Intent intent = new Intent(context, cls);
        context.startActivity(intent);
    }

    private static void checkNotNull(Object obj) {
        if (null == obj) {
            throw new NullPointerException("target should not null!");
        }
    }

    /**
     * 界面跳转，数据回传
     *
     * @param context
     * @param cls
     */
//    public static void startActivityForResult(Context context, Class cls) {
//        checkNotNull(cls);
//        Intent intent = new Intent(context, cls);
//        ((Activity) context).startActivityForResult(intent, Common.REQUEST_CODE_NAME);
//    }
//
//    public static void startDiary(Context context) {
//        Intent intent = new Intent(context, DiaryActivity.class);
//        context.startActivity(intent);
//    }

    /**
     * 选择照片
     */
//    public static void startRecordMenu(Context context, int type, String target) {
//        Intent intent = new Intent(context, PhotoPickerActivity.class);
//        intent.putExtra(PhotoPickerActivity.KEY_TARGET, target);
//        intent.putExtra("type", type);
//        context.startActivity(intent);
//    }

    /**
     * 访群众
     *
     * @param context
     * @param url
     * @param title
     */
    public static void startVisit(Context context, String url, String title) {
//        Intent intent = new Intent(context, VisitWebViewActivity.class);
//        Bundle bundle = new Bundle();
//        bundle.putString("url", url);
//        bundle.putString("title", title);
//        intent.putExtras(bundle);
//        context.startActivity(intent);
    }

    /**
     * 选择单张照片
     *
     * @param context
     */
//    public static void startGalleryForResult(Context context, int cameraFirst) {
//        Intent intent = new Intent(context, PhotoPickerActivity.class);
//        intent.putExtra(PhotoPickerActivity.EXTRA_SELECT_MODE, PhotoPickerActivity.MODE_SINGLE);
//        PhotoPickerActivity.cameraFirst = cameraFirst==0;
//        ((Activity) context).startActivityForResult(intent, Common.REQUEST_CODE_PHOTO);
//    }

    /**
     * 退出当前账号或者退出程序
     *
     * @param context
     * @param b
     */
    public static void choiceExitProgress(Context context, int b) {
//        Intent intent;
//        if (b == 0) {
//            Log.d("TAG", "" + "ffffffff");
//            //点击注销按键后调用LoginActivity提供的resetSprfMain()方法执行SPUtil.put(context, Constant.AUTOLOGIN, false);，即将"Constant.AUTOLOGIN"对应的值修改为false
//            resetSprfMain(context);
//            intent = new Intent(context, LoginActivity.class);
//            intent.putExtra("auto", false);
//            context.startActivity(intent);
//        } else {
////            intent = new Intent(context,ShutDownSystem.class);
//        }
////        context.startActivity(intent);
//        ((Activity) context).finish();
    }

    /**
     * 进入案件详情
     *
     * @param context
     * @param menuId
     */
    public static void startMenuInfoActivity(Context context, String menuId) {
//        Intent intent = new Intent(context, MenuInfoActivity.class);
//        intent.putExtra("menuId", menuId);
//        context.startActivity(intent);
    }

    /**
     * 进入地图
     *
     * @param context
     * @param latitude
     * @param longitude
     */
    public static void startLocationMap(Context context,  String latitude,  String longitude) {
//        Intent intent = new Intent(context, LocationMapActivity.class);
//        intent.putExtra("latitude", latitude);
//        intent.putExtra("longitude", longitude);
//        context.startActivity(intent);
    }

    /**
     * 预览大图
     *
     * @param context
     * @param photoUri
     */
    public static void startPhotoDrawee(Context context, String photoUri) {
//        Intent intent = new Intent(context, PhotoDraweeActivity.class);
//        intent.putExtra(Common.KEY_PHOTO_PREVIEW, photoUri);
//        context.startActivity(intent);
    }


    public static void resetSprfMain(Context context) {
//        SPUtil.put(context, Common.AUTO_LOGIN, false);

    }
}
